#include "matrixfunctions.h" 

void rotate(int mat[][100], int row, char side, int times)
{
	int i, j, t;
	int temp[100][100];
	if(side=='l')
		for (t=0; t<times; t++){
			for(i=0; i<row; i++){
				for(j=0; j<row; ++j)
					temp[row-j-1][i]=mat[i][j];
			}
			for(i=0; i<row; i++)
				for(j=0; j<row; j++)
					mat[i][j]=temp[i][j];
			
		}
	else if(side=='r')
		for (t=0; t<times; t++){
			for(i=0; i<row; i++){
				for(j=0; j<row; ++j)
					temp[j][row-i-1]=mat[i][j];
			}
			for(i=0; i<row; i++)
				for(j=0; j<row; j++)
					mat[i][j]=temp[i][j];
		}
}


int main()
{
	int mat[100][100];
	int row, degrees, times;
	char side;
	cout<<"Number of rows & columns: ";
	cin>>row;
	readmatrix(mat, row, row);
	printmatrix(mat, row, row);
	cout<<"Degrees to rotate : ";
	cin>>degrees;
	cout<<"Side to rotate ('l' for left, 'r' for right) : ";
	cin>>side;
	times=degrees/90;
	rotate(mat, row, side, times);
	printmatrix(mat, row, row);
return 0;
}
